if(!requestScreenCapture()){
    toast("请求截图失败");
    exit();
}
//setScreenMetrics(720, 1280);
var commonModule = require('./common');
var commandModule = require('./command');
launchApp("万国觉醒");
while (!commonModule.isWord()) {
    commandModule.pressNoDelay(46, 490, 30);
    sleep(500)
}
gestures([0, 500, [551, 166], [492, 243]],
    [0, 500, [361, 384], [490, 240]]);

sleep(500)
while(true){
    var templ = images.read("/sdcard/bsg.png");//2160 1080 960 540
    var templ1111=images.scale(templ, device.width/1080,device.height/2160)
    images.save(templ1111, "/sdcard/bsg960*540.png", "png", 100);
    var templ111111 = images.read("/sdcard/bsg960*540.png");
    var gimg=images.grayscale(captureScreen());
    images.save(gimg, "/sdcard/cg.png", "png", 100);
    var gimg2 = images.read("/sdcard/cg.png");
    var p = findImage(gimg2, templ111111, {
        threshold: 0.75
    });
    gimg.recycle();
    gimg2.recycle();
    if(p){
        toast("找到啦:" + p);
        commandModule.pressNoDelay(p.x, p.y, 0);
        sleep(500)
            commandModule.pressNoDelay(460, 280, 0);
            sleep(500)
            var p3=commandModule.findImage("cj.png");
            if(p3){
                commandModule.pressNoDelay(p3.x, p3.y, 0);
                sleep(500)
                var p4=commandModule.findImage("cjbd.png");
                if(p4){
                    commandModule.pressNoDelay(p4.x, p4.y, 0);
                    sleep(500)
                    var p5=commandModule.findImage("xj.png");
                    if(p5){
                        commandModule.pressNoDelay(p5.x, p5.y, 0);
                        sleep(500)
                        gestures([0, 500, [551, 166], [492, 243]],
                            [0, 500, [361, 384], [490, 240]]);
                        
                    }
                }
            }
    }else{
        toast("没找到");
    }
    templ.recycle();
    sleep(2000)
}
